home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Leonardo the Inventor
/
Leonardo The Inventor (93026)(Broderbund)(Riverdeep)(2004).iso
/
LEOWINMV
/
DATABASE.DIR
/
00111_Script_ADD TITLES TO INDEX
< prev
next >
Wrap
Text File
|
1996-03-28
|
9KB
|
241 lines
-- ---------------------------------------------------------------
-- NOTE: TO MAKE THIS WORK, THE LIST OF WORDS IN FIELD
-- "NONSEARCHABLEBROWSERWORDS" MUST BE IN REVERSE ALPHABETICAL ORDER!!!
-- ---------------------------------------------------------------
on addtitlesToIndex
getNonSearchableBrowserWords
reverseSortNonSearchableWords
addNonSearchableWordsToIndex
end
-- --------------------------------------------------------------
-- Handler getNonSearchableBrowserWords return a lisf of words in the browser topics
-- that are not searchable.
on getNonSearchableBrowserWords
initIndexIndex
set browser = field "browserTopics"
set searchline = 1
repeat with i = 1 to the number of lines in browser
repeat with j = 1 to the number of words in line i of browser
set currentWord = word j of line i of browser
if endsWithPunctuation(currentWord) then
set currentWord = removePunctuationFromEnd(currentWord)
end if
if beginsWithPunctuation(currentWord) then
set currentWord = removePunctuationFromBeginning(currentWord)
end if
if isIgnorableWord(currentWord) then
next repeat
end if
set searchResults = getIndexIndexData(currentWord)
if (searchResults = EMPTY) then
put currentWord & ":" & line i of browser into line searchline of field "nonSearchableBrowserWords"
set searchline = searchline + 1
else if NOT(searchResults contains line i of browser) then
put currentWord & ":" & line i of browser into line searchline of field "nonSearchableBrowserWords"
set searchline = searchline + 1
end if
end repeat
put "finished" && line i of browser
end repeat
end
-- ---------------------------------------------------------------
-- Handler addNonSearchableWordsToIndex takes the words in field
-- nonSearchableWords and adds them to the appropriate index fields.
-- NOTE: to make this reusable, change the format of the field
-- nonSearchableWords.
on addNonSearchableWordsToIndex
global nonSearchableBrowserWords
set nonSearchableBrowserWords = field "nonSearchableBrowserWords"
repeat with i = 1 to the number of lines in nonSearchableBrowserWords
set the itemDelimiter = ":"
-- get the nonSearchable word
set newWord = item 1 of line i of nonSearchableBrowserWords
put newWord
-- get the browser topic containing the nonSearchable word
set browserTopic = item 2 of line i of nonSearchableBrowserWords
-- search the indexIndex for the word
set indexCastAndLineList = getIndexCastAndLine(newWord)
set indexCast = getAt(indexCastAndLineList,2)
set indexCastLine = getAt(indexCastAndLineList,3)
-- determine if the word exists as an entry or not
set existsAlreadyFlag = getAt(indexCastAndLineList,1)
if existsAlreadyFlag then
-- the entry already exists, just needs to be updated
updateEntryInIndex(newWord, browserTopic, indexCast, indexCastLine, existsAlreadyFlag)
else
-- the entry doesn't exist, add it
-- get the new entry
set newEntry = getNewEntry(newWord,list(browserTopic))
-- add the entry to the index
addSingleEntryToIndex(newEntry, indexCast, indexCastLine)
end if
end repeat
set the itemDelimiter = ","
end
-- ---------------------------------------------------------------
-- Handler getIndexCastAndLine
on getIndexCastAndLine wordToAdd
-- start with the first indexIndex. See if it fits in there. If so,
-- get the cast to add to from item 2 of the line. If not, move on
-- to indexIndex 2, 3, and so on until 12.
repeat with i = 1 to 13
set theIndexIndex = field("indexIndex" && i)
set indexCastAndLine = getEntryLocation(wordToAdd, theIndexIndex)
if (indexCastAndLine = -1) then -- doesn't fit in this indexIndex
next repeat
else
return indexCastAndLine
end if
end repeat
if (i = 13) then -- didn't fit in any indexIndex, add to last index
alert "need to add at end of 13"
end if
end
-- ---------------------------------------------------------------
-- Handler getEntryLocation
on getEntryLocation wordToAdd, theIndexIndex
-- get the last line in the indexIndex that has an entry
set continue = TRUE
set indexIndexLines = the number of lines in theIndexIndex
repeat while continue
if (item 1 of line indexIndexLines of theIndexIndex = EMPTY) then
set indexIndexLines = indexIndexLines - 1
else
set continue = FALSE
end if
end repeat
-- quick check: if wordToAdd > the last entry then it doesn't fit in this indexIndex
if (item 1 of line indexIndexLines of theIndexIndex < wordToAdd) then
return -1
else -- fits in this indexIndex
repeat with i = 1 to indexIndexLines
if (item 1 of line i of theIndexIndex > wordToAdd) then
return list(0,value(item 2 of line i of theIndexIndex), value(item 3 of line i of theIndexIndex))
else if (item 1 of line i of theIndexIndex = wordToAdd) then
-- entry already exists, just update its search results
-- return as the first item of the list, the line number of
-- the next index entry.
return list(value(item 3 of line (i+1) of theIndexIndex),value(item 2 of line i of theIndexIndex), value(item 3 of line i of theIndexIndex))
end if
end repeat
end if
return -1 -- didn't fit in then indexIndex
end
-- ---------------------------------------------------------------
-- Handler getNewEntry puts the given entry and entryList in index
-- format (asterisk followed by entry followed by return followed
-- by list of articles containing the entry)
on getNewEntry entry, entryList
set newEntry = "*" & entry
repeat with i = 1 to count(entryList)
set newEntry = newEntry & RETURN & getAt(entryList,i)
end repeat
return newEntry
end
-- ---------------------------------------------------------------
-- Handler addSingleEntryToIndex adds the given entry to the given
-- indexCast before the given indexCastLine
on addSingleEntryToIndex newEntry, indexCast, indexCastLine
set numLines = the number of lines in the text of cast indexCast
set beforeEntryIndex = line 1 to (indexCastLine-1) of the text of cast indexCast
set afterEntryIndex = line indexCastLine to numLines of the text of cast indexCast
set newIndex = beforeEntryIndex & RETURN & newEntry & RETURN & afterEntryIndex
set the text of cast indexCast = newIndex
end
-- ---------------------------------------------------------------
-- Handler updateEntryInIndex adds the given line to the search results
-- of the given newWord. The previous search results are found
-- in the given indexCast at the given indexCastLine. NOTE: can't
-- use indexIndex to get the starting line of the next index entry
-- because this code will be chaning the index casts and the numbers
-- in the index index will no longer be relevant.
on updateEntryInIndex newWord, newTopic, indexCast, indexCastLine, nextEntryLine
set numLines = the number of lines in the text of cast indexCast
set beforeEntryIndex = line 1 to (indexCastLine-1) of the text of cast indexCast
set afterEntryIndex = line nextEntryLine to numLines of the text of cast indexCast
set oldEntry = getEntry(indexCast, indexCastLine, nextEntryLine)
set newEntry = getEntryWithAddedTopic(oldEntry, newTopic)
set newIndex = beforeEntryIndex & RETURN & newEntry & RETURN & afterEntryIndex
set the text of cast indexCast = newIndex
end
-- ---------------------------------------------------------------
-- Handler getEntry returns the entry between the given lines of the
-- given indexCast.
on getEntry indexCast, indexCastLine, nextEntryLine
return line indexCastLine to (nextEntryLine - 1) of the text of cast indexCast
end
-- ---------------------------------------------------------------
-- Handler getEntryWithAddedTopic returns the new entry composed
-- of the given oldEntry with the newTopic inserted in the proper
-- place.
on getEntryWithAddedTopic oldEntry, newTopic
set entryWithAddedTopic = line 1 of oldEntry -- "*" && the word
set numLines = the number of lines in oldEntry
repeat with i = 2 to numLines
if (line i of oldEntry > newTopic) then
return entryWithAddedTopic & RETURN & newTopic & RETURN & line i to numLines of oldEntry
else
set entryWithAddedTopic = entryWithAddedTopic & RETURN & line i of oldENTRY
end if
end repeat
return entryWithAddedTopic & RETURN & newTopic
end
on reverseSortNonSearchableWords
set numLines = the number of lines in field "nonSearchableBrowserWords"
set list = []
repeat with i = 1 to numLines
add list, line i of field "nonSearchableBrowserWords"
end repeat
sort list
put empty into field "nonSearchableBrowserWords"
repeat with i = numLines down to 1
put getAt(list, i) & RETURN after field "nonSearchableBrowserWords"
end repeat
end